package in.muton.edushare.newentities.upgraded;

import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.model.IModel;

import com.edushare.common.vo.Batches;
import com.edushare.common.vo.CourseInstances;
import com.edushare.common.vo.Departments;
import com.edushare.common.vo.Enrolments;
import com.edushare.common.vo.GroupMembers;
import com.edushare.common.vo.Groups;
import com.edushare.common.vo.Poll;
import com.edushare.common.vo.Universities;
import com.edushare.common.vo.UserDeptLink;
import com.edushare.common.vo.UserPoll;
import com.edushare.common.vo.UserRoles;

public class RoleManagement {
	public static Log log = LogFactory.getLog(RoleManagement.class);
	
	public static HashMap<String, Integer> getRoles(IModel<?> model) {
		HashMap<String, Integer> map;
		if (model.getObject() instanceof Batches){
			map = emptyMap;
			log.debug("Returning a batch map with size "+map.size());
		}else if (model.getObject() instanceof CourseInstances){
			map = courseMap;
			log.debug("Returning a course map with size "+map.size());
		}else if (model.getObject() instanceof Departments){
			map = deptMap;
			log.debug("Returning a department map with size "+map.size());
		}else if (model.getObject() instanceof Universities){
			map = univMap;
			log.debug("Returning a university map with size "+map.size());
		}else if (model.getObject() instanceof Groups){
			map = groupMap;
			log.debug("Returning a group map with size "+map.size());
		}else if(model.getObject() instanceof Poll){
			map =  pollMap;
			log.debug("Returning a poll map with size "+map.size());
		}else{
			map = emptyMap;
			log.debug("Returning a unknown map with size "+map.size());
		}
		return map;
	}

	private static HashMap<String, Integer> emptyMap = new HashMap<String, Integer>();
	private static HashMap<String, Integer> courseMap = new HashMap<String, Integer>();
	static {
		courseMap.put("Faculty", Enrolments.TEACHER);
		courseMap.put("Teaching Assistant", Enrolments.TEACHING_ASSISTANT);
		courseMap.put("Student", Enrolments.STUDENT);
		courseMap.put("Audit Student", Enrolments.OBSERVER);
	}
	private static HashMap<String, Integer> deptMap = new HashMap<String, Integer>();
	static {
		deptMap.put("Administrators", UserDeptLink.PRIMARY_ADMIN);
		deptMap.put("Faculty", UserDeptLink.TEACHER);
		deptMap.put("Student", UserDeptLink.STUDENT);
	}
	private static HashMap<String, Integer> univMap = new HashMap<String, Integer>();
	static{
		univMap.put("Administrator", UserRoles.ADMIN_ROLE);
		univMap.put("Faculty", UserRoles.TEACHER_ROLE);
		univMap.put("Student", UserRoles.STUDENT_ROLE);
	}
	private static HashMap<String, Integer> groupMap = new HashMap<String, Integer>();
	static{
		groupMap.put("Group Administrator", GroupMembers.GROUP_ADMIN);
		groupMap.put("Group Member", GroupMembers.GROUP_MEMBER);
	}
	private static HashMap<String, Integer> pollMap = new HashMap<String, Integer>();
	static{
		pollMap.put("Poll Participants", UserPoll.ROLE_RESPONDENT);
		pollMap.put("Poll Reviewers", UserPoll.ROLE_REVIEWER);
	}

}
